﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using CanalDeNoticiasMSDN.ViewModels;
using Microsoft.Phone.Tasks;

namespace CanalDeNoticiasMSDN
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            App.ViewModel.LoadData();
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                ElementoEntradaVideo element = e.AddedItems[0] as ElementoEntradaVideo;
                if (element != null)
                {
                    new MediaPlayerLauncher
                    {
                        Media = new Uri(element.Video),
                        Controls = MediaPlaybackControls.All
                    }.Show();
                }
            }
        }

        private void ListBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                ElementoEntradaRss element = e.AddedItems[0] as ElementoEntradaRss;
                if (element != null)
                {
                    new WebBrowserTask
                    {
                        URL = element.Link
                    }.Show();
                }
            }
        }

    }
}